// components/scroll-row-module/index.ts
const app = getApp();
const hideScrollBar = require("../../behavior/hide-scroll-bar");
import { preparePullLiveStream } from '../../api/index';
const videoIntersectionObserver = require("../../behavior/videoIntersectionObserver")
Component({
  /**
   * 组件的属性列表
   */
  behaviors: [hideScrollBar, videoIntersectionObserver],
  properties: {
    mode: {
      type: Number,
      value: 0
    },
    moduleData: {
      type: Object,
      value: {
        title: "标题名称",
        list: []
      }
    },
    itemWidth: {
      type: String,
      value: `300rpx`
    },
    itemHeight: {
      type: String,
      value: `${300 * 9 / 16}rpx`
    }
  },
  lifetimes: {
    created() {
      // console.log(this.properties.mode);

    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    windowWidth: app.globalData.windowWidth,
    whiteArr: ["我的短视频", "短视频收藏"]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    tapCardItem(event) {
      if (this.properties.mode == 0) {
        app.globalData.currentPlayVideoID = event.currentTarget.dataset.code;
        app.globalData.currentPlayElv = event.currentTarget.dataset.elvname;
        app.globalData.CameraOrigin = event.currentTarget.dataset.cameraorigin;
        app.globalData.currentEnterPriseID = event.currentTarget.dataset.enterpriseid;
        let title = event.currentTarget.dataset.title
        const pages = getCurrentPages()
        let currentPage = pages[pages.length - 1]
        if (currentPage.route == "pages/enterprise/views/home/index") {
          wx.navigateBack()
        } else {
          wx.navigateTo({
            url: `/pages/play-page/index?title=${title}`
          })
        }
      } else {//我的短视频、短视频收藏
        const { value } = event.currentTarget.dataset;
        const type = this.data.whiteArr.indexOf(this.properties.moduleData.title)
        const url = `/pages/user/short-video/video-show-page/index?id=${value.id}&type=${type}`
        wx.navigateTo({
          url: url
        })
      }
    },
    goToMorePage() {
      wx.navigateTo({
        url: `/pages/more-page/index?pageTitle=${this.properties.moduleData.title}`
      })
    },

    longPress(event) {
      console.log("长按");
      let info = event.currentTarget.dataset
      this.triggerEvent("itemLongPress", info)
    }
  },
  observers: {
    moduleData(val) {

      if (val && val.list.length > 0 && this.properties.mode == 0) {
        this.observe((res: any) => {
          let value = res.dataset.value
          if (value.code && value.elvName && app.globalData.token) {
            preparePullLiveStream({
              CamID: value.code,
              ELVName: value.elvName
            })
          }
        }, ".row-item")
      }
    }
  }
})

export { }